const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../services/user.js');

//获取应用实例
const app = getApp()
Page({
  data: {
    bestGoods: [],
    checkname:"",
    id:0
  },
  onShareAppMessage: function () {
    return {
      title: '神画官网微信小程序商城',
      desc: '神画官网微信小程序商城',
      path: '/pages/index/index'
    }
  },
  getCatData: function (id) {
    let that = this;
    util.request(api.catDetailUrl,{id:id}).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          bestGoods: res.data,
          checkname:"",
          id:id
        });
      }
    });
  },
  switchsearch: function (event){
    let that = this;
    let name = event.currentTarget.dataset.name;
    if(name!=""){
    util.request(api.searchData, {keywords:name}).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          bestGoods: res.data,
          checkname: name
        });
      }
    });
    }
  },
  onLoad: function (options) {
    let id=options.id;
    let newtitle=id==14 ?"智能影院":"精品配件";
    wx.setNavigationBarTitle({
      title: newtitle
    })
    this.getCatData(id);
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
})
